<!DOCTYPE html>
<html>
<head>
	<title>提交线索</title>
	<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" type="text/css" href="layui/css/layui.css">
    
    <style type="text/css">
    	.layui-row{
    		margin-top:10px;
    	}
    	.fei{
    		position: fixed;
    		right:250px;
    		top:50px;

    	}
    </style>
</head>
<body style="padding:50px;">


	<div class="layui-container">
		<div class="layui-row" >
	      <div class="layui-col-md2">
	              
	              <a href="jiemian.php"><i class="layui-icon layui-icon-left" style="font-size:20px"></i><div class="doc-icon-name">返回</div></a>

	      </div>
	    </div>
	    <hr>

		<div class="layui-row">
			<div class="layui-col-md5">
				<div class="layui-inline">
			          <label >日期选择：</label>
		        </div>
		        <div class="layui-input-inline">
		          <input type="text" id="dateA" class="layui-input" style="width:200px;">
	       		</div>
	       		<div class="layui-inline">
	       			<button class="layui-btn" onclick="updateTable()">查询</button>
	       		</div>

			</div>
			<div class="layui-col-md7">
				<button class="layui-btn" onclick="piLiangSubmit()">批量提交</button>
			</div>
		</div>
		<div class="layui-row">

			<div class="layui-col-md6">
				<h2 id="count"></h2>
			</div>
			
			
		</div>
		<div class="layui-row">
			<div class="layui-col-md12">
				<table id="tab" width="550px" hidden="550px" lay-filter="test">
					
				</table>
			</div>
			
		</div>
	</div>

<!-- 	<div class="fei">
				<iframe src="http://qumei.243000.net/form.html" width="500px" height="800px"></iframe>
	</div> -->

</body>
</html>
<script src="layui/layui.all.js"></script>
<script src="copy.js"></script>
<script type="text/javascript">

	var laydate=layui.laydate

	var myDate=new Date();

	var starDateY=myDate.getFullYear()+'-'+(myDate.getMonth()+1)+'-'+myDate.getDate()

	var day1 = new Date();

	 day1.setTime(day1.getTime()+24*1000*60*60);

	var endDateY = day1.getFullYear()+"-" + (day1.getMonth()+1) + "-" + day1.getDate();

	laydate.render({
		elem:'#dateA',
		range:true,
		value:starDateY+' - '+endDateY,
		change: function(value, date, endDate){
		    // console.log(value); //得到日期生成的值，如：2017-08-18
		    // console.log(date); //得到日期时间对象：{year: 2017, month: 8, date: 18, hours: 0, minutes: 0, seconds: 0}
		    // console.log(endDate); //得结束的日期时间对象，开启范围选择（range: true）才会返回。对象成员同上。

		    updateTable(value)
		}
		
	})
	



	var table=layui.table

	var yixiang={'field':'yxRiqi',title:'意向',sort:true,width:190,templet:function(d){

		

		if(d.yxRiqi == null){

			return '无记录'
		}else{

			return '点击链接'

		}

	}}

	var submit={field:'sumbit',title:'提交',sort:true,templet:function(d){

		console.log(d.sumbit)
		if(d.submit==null){

			return '未提交'
		}else{
			return '已提交'
		}
	}}

	var ziZhangHao_field=[{field:'riqi',title:'来源日期',sort:true},{'field':'tell',title:'手机号码',sort:true},{field:'shengFen',title:'省份',sort:true},{field:'city',title:'城市',sort:true},yixiang,submit] //,{field:'',title:'复制',sort:true,templet: '#titleTpl'}

	table.render({

		elem:'#tab',
		url:'mingxi.php',
		cols:[ziZhangHao_field],
		method:'post',
		where:{type:38,starTime:starDateY,endTime:endDateY},
		done:function(res){


			$('#count').text('共'+res.msg+'条数据')
		}

	})

	table.on('row(test)', function(obj){

	  console.log(obj.data)  //复制

	  var da=obj.data

	  if(da.submit==null&&da.yxRiqi!==null){

	  	yibuSumbit(da.tell,da.shengFen+da.city,'测试');


	  }else{

	  	var layer=layui.layer

	  	layer.msg('失败,已提交或无记录')
	  }

	  


	});


	function updateTable(date){

     	

     	if(date==undefined){

     		var datstr=$('#dateA')[0].value

     		var date_rag=datstr.match(/\d{4}-\d{1,2}-\d{1,2}/g);

     	}else{
     		var date_rag=date.match(/\d{4}-\d{1,2}-\d{1,2}/g);
     	}

     	

        table.reload('tab',{

	        where:{

	          type:38,	
	          starTime:date_rag[0],
	          endTime:date_rag[1]
	        }

        })


     }

    function yibuSumbit(tell,city,remark,on=1){



    		$.post(
    			'tt.php',
    			{realname:'',tel:tell,city:city,wechat:'',remark:remark},
    			function(data,status){

    				if(on==1){
						var layer=layui.layer;
	    				
	    				var data=JSON.parse(data)
	    				console.log(data.msg)

	    				layer.msg(data.msg)

	    				updateTable()

    				}else{


    					console.log(data)
    				}

    				

    			}
    		)


    }

    function piLiangSubmit(){


    	$.post(

    		'mingxi.php',
    		{type:39,},
    		function(data,status){

    			var arr=JSON.parse(data)

    			arr=arr.data

    			console.log(arr)

    			for(var i=0;i<arr.length;i++){

    				yibuSumbit(arr[i].tell,arr[i].shengFen+arr[i].city,'测试',2)

    			}
    		}
    	)


    }

</script>

<!-- <script type="text/html" id="titleTpl">
 	<span>
 		<img width="25px" height="25px" src="https://common.cnblogs.com/images/copycode.gif" onclick="copyToClipboard('{{d.tell}}',0)">
 		<img width="25px" height="25px" src="https://common.cnblogs.com/images/copycode.gif" onclick="copyToClipboard('{{d.city}}',1)">
 	</span>
</script> -->